package idv.loveloser.dao;

import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for
 * MdlGradeItemsHistory entities. Transaction control of the save(), update()
 * and delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see idv.loveloser.dao.MdlGradeItemsHistory
 * @author MyEclipse Persistence Tools
 */

public class MdlGradeItemsHistoryDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory
			.getLogger(MdlGradeItemsHistoryDAO.class);
	// property constants
	public static final String ACTION = "action";
	public static final String OLDID = "oldid";
	public static final String SOURCE = "source";
	public static final String TIMEMODIFIED = "timemodified";
	public static final String LOGGEDUSER = "loggeduser";
	public static final String COURSEID = "courseid";
	public static final String CATEGORYID = "categoryid";
	public static final String ITEMNAME = "itemname";
	public static final String ITEMTYPE = "itemtype";
	public static final String ITEMMODULE = "itemmodule";
	public static final String ITEMINSTANCE = "iteminstance";
	public static final String ITEMNUMBER = "itemnumber";
	public static final String ITEMINFO = "iteminfo";
	public static final String IDNUMBER = "idnumber";
	public static final String CALCULATION = "calculation";
	public static final String GRADETYPE = "gradetype";
	public static final String GRADEMAX = "grademax";
	public static final String GRADEMIN = "grademin";
	public static final String SCALEID = "scaleid";
	public static final String OUTCOMEID = "outcomeid";
	public static final String GRADEPASS = "gradepass";
	public static final String MULTFACTOR = "multfactor";
	public static final String PLUSFACTOR = "plusfactor";
	public static final String AGGREGATIONCOEF = "aggregationcoef";
	public static final String SORTORDER = "sortorder";
	public static final String HIDDEN = "hidden";
	public static final String LOCKED = "locked";
	public static final String LOCKTIME = "locktime";
	public static final String NEEDSUPDATE = "needsupdate";
	public static final String DISPLAY = "display";
	public static final String DECIMALS = "decimals";

	public void save(MdlGradeItemsHistory transientInstance) {
		log.debug("saving MdlGradeItemsHistory instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(MdlGradeItemsHistory persistentInstance) {
		log.debug("deleting MdlGradeItemsHistory instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public MdlGradeItemsHistory findById(java.lang.Long id) {
		log.debug("getting MdlGradeItemsHistory instance with id: " + id);
		try {
			MdlGradeItemsHistory instance = (MdlGradeItemsHistory) getSession()
					.get("idv.loveloser.dao.MdlGradeItemsHistory", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(MdlGradeItemsHistory instance) {
		log.debug("finding MdlGradeItemsHistory instance by example");
		try {
			List results = getSession()
					.createCriteria("idv.loveloser.dao.MdlGradeItemsHistory")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding MdlGradeItemsHistory instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from MdlGradeItemsHistory as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByAction(Object action) {
		return findByProperty(ACTION, action);
	}

	public List findByOldid(Object oldid) {
		return findByProperty(OLDID, oldid);
	}

	public List findBySource(Object source) {
		return findByProperty(SOURCE, source);
	}

	public List findByTimemodified(Object timemodified) {
		return findByProperty(TIMEMODIFIED, timemodified);
	}

	public List findByLoggeduser(Object loggeduser) {
		return findByProperty(LOGGEDUSER, loggeduser);
	}

	public List findByCourseid(Object courseid) {
		return findByProperty(COURSEID, courseid);
	}

	public List findByCategoryid(Object categoryid) {
		return findByProperty(CATEGORYID, categoryid);
	}

	public List findByItemname(Object itemname) {
		return findByProperty(ITEMNAME, itemname);
	}

	public List findByItemtype(Object itemtype) {
		return findByProperty(ITEMTYPE, itemtype);
	}

	public List findByItemmodule(Object itemmodule) {
		return findByProperty(ITEMMODULE, itemmodule);
	}

	public List findByIteminstance(Object iteminstance) {
		return findByProperty(ITEMINSTANCE, iteminstance);
	}

	public List findByItemnumber(Object itemnumber) {
		return findByProperty(ITEMNUMBER, itemnumber);
	}

	public List findByIteminfo(Object iteminfo) {
		return findByProperty(ITEMINFO, iteminfo);
	}

	public List findByIdnumber(Object idnumber) {
		return findByProperty(IDNUMBER, idnumber);
	}

	public List findByCalculation(Object calculation) {
		return findByProperty(CALCULATION, calculation);
	}

	public List findByGradetype(Object gradetype) {
		return findByProperty(GRADETYPE, gradetype);
	}

	public List findByGrademax(Object grademax) {
		return findByProperty(GRADEMAX, grademax);
	}

	public List findByGrademin(Object grademin) {
		return findByProperty(GRADEMIN, grademin);
	}

	public List findByScaleid(Object scaleid) {
		return findByProperty(SCALEID, scaleid);
	}

	public List findByOutcomeid(Object outcomeid) {
		return findByProperty(OUTCOMEID, outcomeid);
	}

	public List findByGradepass(Object gradepass) {
		return findByProperty(GRADEPASS, gradepass);
	}

	public List findByMultfactor(Object multfactor) {
		return findByProperty(MULTFACTOR, multfactor);
	}

	public List findByPlusfactor(Object plusfactor) {
		return findByProperty(PLUSFACTOR, plusfactor);
	}

	public List findByAggregationcoef(Object aggregationcoef) {
		return findByProperty(AGGREGATIONCOEF, aggregationcoef);
	}

	public List findBySortorder(Object sortorder) {
		return findByProperty(SORTORDER, sortorder);
	}

	public List findByHidden(Object hidden) {
		return findByProperty(HIDDEN, hidden);
	}

	public List findByLocked(Object locked) {
		return findByProperty(LOCKED, locked);
	}

	public List findByLocktime(Object locktime) {
		return findByProperty(LOCKTIME, locktime);
	}

	public List findByNeedsupdate(Object needsupdate) {
		return findByProperty(NEEDSUPDATE, needsupdate);
	}

	public List findByDisplay(Object display) {
		return findByProperty(DISPLAY, display);
	}

	public List findByDecimals(Object decimals) {
		return findByProperty(DECIMALS, decimals);
	}

	public List findAll() {
		log.debug("finding all MdlGradeItemsHistory instances");
		try {
			String queryString = "from MdlGradeItemsHistory";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public MdlGradeItemsHistory merge(MdlGradeItemsHistory detachedInstance) {
		log.debug("merging MdlGradeItemsHistory instance");
		try {
			MdlGradeItemsHistory result = (MdlGradeItemsHistory) getSession()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(MdlGradeItemsHistory instance) {
		log.debug("attaching dirty MdlGradeItemsHistory instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(MdlGradeItemsHistory instance) {
		log.debug("attaching clean MdlGradeItemsHistory instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}